import React, { Component } from 'react'
import ReactDOM from 'react-dom'

class App extends Component {
  constructor(props) {
    super(props)
    console.log(`constructor`, 1);
    //1.提供数据
    //2.提供ref
    //3.绑定this指向
    this.state = {
      msg: 123,
      count: 1
    }
    this.inputRef = React.createRef()
  }
  render() {
    console.log(`render`, 2);
    return (
      <div>
        <h1>App组件</h1>
        <button onClick={this.handleClick}>按钮</button>
        <p>{this.state.count}</p>
      </div>
    )
  }
  handleClick = () => {
    // this.setState({
    //   count: this.state.count + 1
    // })
    // this.state.count++
    this.forceUpdate() //强制更新
  }
  componentDidMount() {
    console.log(`componentDidMount`, 3);
  }
  componentDidUpdate() {
    console.log(`componentDidMount`, 4);
  }
  componentWillUnmount() {
    //销毁生命周期---释放资源，全局事件，定时器
  }
}

ReactDOM.render(<App></App>, document.getElementById('root'))